// pages/xiaoxi/shenpi/index.js
const myRequest = require("../../../utils/require.js")
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showModal:null,
    userInfo: '',
    list:[],
    next:1,
    page:1,
    bohui_id:'',
    refuse:'',
    status:0,

  },
  chuli(e){
  let status =e.currentTarget.dataset.status
  console.log(status)
  this.setData({
    status,
    list:[],
    next:1,
    page:1
  })
  this.apiRequset()

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.CheckSession().then(res => {
      if (res == true) {
        app.GetUser().then(data => {
          this.setData({
            userInfo: data
          })
          this.apiRequset()

        })
      }
    })
  },
  apiRequset(){
    if(this.data.next==null){
      return 
    }
  
    myRequest.myRequest('DisSource/shenpi', {page:this.data.page,status:this.data.status}, 'GET').then(list => {
      console.log(list)
      let page = this.data.page
      let data=this.data.list
      data= data.concat(list.data)
      page++
      this.setData({
        list: data,
        page:page,
        next:list.links.next
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.apiRequset()
  },
  /**
   * 审核通过
   */
  Tongyi(e){
    console.log(e)
    let id=e.target.dataset.id
    wx.showModal({
      title: '确定同意审核么?',
      content: '',
      showCancel: true,
      cancelText: '取消',
      cancelColor: '',
      confirmText: '确定',
      confirmColor: '',
      success: res=> {
        if(res.confirm){
          myRequest.myRequest('DisSource/shenhe/' + id, {}, 'POST').then(data => {
            console.log(data)
            app.BackUpdate()
            if (data.code=="success"){
            let list=this.data.list
            let index=  list.findIndex((value,index,arr)=>{
                return value.id==id
              })
             list[index].status=1
             this.setData({
               list:list
             }) 
            }
          }
        )
       }
      },
      fail: function(res) {},
      complete: function(res) {},
    })
    
  },
  /**
 * 驳回
 */
Bohui(e) {
  let id = e.target.dataset.id
  this.setData({
    showModal:'1',
    bohui_id:id
  })
  },
  CancelBohui(e) {
    this.setData({
      showModal: null,
      bohui_id: ''
    })
  },
  SureBohui(e){
    console.log(e.detail.value.refuse)
    myRequest.myRequest('DisSource/refuse/' + this.data.bohui_id, { refuse: e.detail.value.refuse},'POST').then(
        res=>{
            if(res.code=="success"){
              app.BackUpdate()
              let list = this.data.list
              let index = list.findIndex((value, index, arr) => {
                return value.id == this.data.bohui_id
              })
              list[index].status = 2
              this.setData({
                list: list,
                showModal: null,
              }) 
            }else{
              wx.showToast({
                title: res.message,
                icon: '',
                image: '',
                duration: 0,
                mask: true,
                success: function (res) { },
                fail: function (res) { },
                complete: function (res) { },
              })
            }
        }
    )
  }









},



)

